//
//  SchoolTableViewCell.m
//  BOSS-SOOC
//
//  Created by apple on 16/8/12.
//  Copyright © 2016年 Gcx. All rights reserved.
//

#import "SchoolTableViewCell.h"
#import "SchoolModel.h"

@implementation SchoolTableViewCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
        
        _titleImage = [UIImageView new];
        _titleImage.image = [UIImage imageNamed:@"page_1.png"];
        [self.contentView addSubview:_titleImage];
        
        [_titleImage  mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.top.equalTo(self.contentView).with.offset(39*Bili);
            make.left.equalTo(self.contentView).with.offset(33*Bili);
            make.bottom.equalTo(self.contentView).with.offset(-39*Bili);
            make.right.equalTo(self.contentView.mas_centerX).with.offset(-29*Bili);
        }];
        
        //小锁的图片
        _lockImg = [[UIImageView alloc]init];
        [_titleImage addSubview:_lockImg];
        _lockImg.image = [UIImage imageNamed:@"课程加密"];
        [_lockImg mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.and.height.mas_equalTo(@(20));
            make.bottom.equalTo(_titleImage);
            make.right.equalTo(_titleImage);
        }];
        
        _lockImg.hidden = YES;
        
        _titleLabel = [[UILabel alloc]init];
        _titleLabel.text = @"创业微访谈";
        _titleLabel.font = NormalFont(42);
        //        _titleLabel.numberOfLines = 2;
        
        _titleLabel.textColor = Color333333;
        _titleLabel.lineSpace = 10*Bili;
        [self.contentView addSubview:_titleLabel];
        [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_titleImage.mas_top);
            make.left.equalTo(_titleImage.mas_right).offset(Bili*33);
            make.right.equalTo(self.contentView.mas_right).offset(-Bili*33);
            make.width.mas_equalTo(@(32));
        }];
        self.titleLabel.lineBreakMode = NSLineBreakByTruncatingTail;
        self.titleLabel.numberOfLines = 2;
        
        
        _pjView = [UIView new];
        _pjView.backgroundColor = [UIColor whiteColor];
        [self.contentView addSubview:_pjView];
        
        [_pjView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView.mas_centerX).with.offset(0);
            make.bottom.equalTo(_titleImage.mas_bottom).with.offset(0);
            make.size.mas_equalTo(CGSizeMake(240*Bili , 40*Bili));
            
        }];
        
        
        _smallImage = [UIImageView new];
        _smallImage.image = [UIImage imageNamed:@"我的-课程发布人"];
        [self.contentView addSubview:_smallImage];
        
        [_smallImage mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.top.equalTo(self.contentView.mas_bottom).with.offset(-162*Bili);
            make.left.equalTo(self.contentView.mas_centerX).with.offset(0);
            make.size.mas_equalTo(CGSizeMake(48*Bili, 48*Bili));
            
        }];
        
        _nameLabel = [UILabel new];
        _nameLabel.text = @"李老师";
        _nameLabel.font = NormalFont(33);
        
        _nameLabel.textColor = Color999999;
        [self.contentView addSubview:_nameLabel];
        
        [_nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.left.equalTo(_smallImage.mas_right).with.offset(24*Bili);
            make.bottom.equalTo(_smallImage.mas_bottom).with.offset(2);
            make.size.mas_equalTo(CGSizeMake(CGRectGetWidth(self.contentView.frame)/2-2*33*Bili-15-24*Bili, 20));
            
        }];
        
        _peopleLable = [UILabel new];
        _peopleLable.text = @"30个人看过";
        _peopleLable.font = NormalFont(33);
        _peopleLable.textAlignment = NSTextAlignmentRight;
        _peopleLable.textColor = Color999999;
        [self.contentView addSubview:_peopleLable];
        
        [_peopleLable mas_makeConstraints:^(MASConstraintMaker *make) {
            
            //            make.top.equalTo(self.contentView).with.offset(gap);
            make.right.equalTo(self.contentView).with.offset(-33*Bili);
            make.bottom.equalTo(_titleImage.mas_bottom).with.offset(4);
            make.size.mas_equalTo(CGSizeMake(100, 20));
            
        }];
        _line = [[UIView alloc]init];
        _line.backgroundColor = colordbdbdb;
        [self.contentView addSubview:_line];
        [_line mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView.mas_left).offset(33*Bili);
            make.right.equalTo(self.contentView.mas_right).offset(0);
            make.bottom.equalTo(self.contentView.mas_bottom).offset(-0.5);
            make.height.mas_equalTo(0.5);
        }];
    }
    
    return self;
}

- (void)setMyModel:(SchoolModel *)myModel{
    
    _myModel = myModel;
    
    [self.titleImage sd_setImageWithURL:[NSURL URLWithString:myModel.kcfm] placeholderImage:nil options:SDWebImageCacheMemoryOnly];

    self.titleLabel.text = myModel.kcmc;
    
    CGRect h = [self.titleLabel getLableHeightWithMaxWidth:SIZEWIDTH - 277*Bili - 99*Bili];
    
    _titleLabel.frame = CGRectMake(CGRectGetMaxX(self.titleImage.frame)+33*Bili, 39*Bili, h.size.width, h.size.height);
    
    self.nameLabel.text = myModel.kcjs;
    
    self.peopleLable.text = [NSString stringWithFormat:@"%@人学习", myModel.kcrs];
    
    NSInteger number = [myModel.kcpj integerValue];
    
    for (UIView *view in self.pjView.subviews) {
        [view removeFromSuperview];
    }
    
    for (int i = 0; i < number; i++) {
        
        UIImageView *image = [[UIImageView alloc]initWithFrame:CGRectMake(i*40*Bili, 0, 40*Bili, 40*Bili)];
        image.image = [UIImage imageNamed:@"弹窗评价-pass"];
        [self.pjView addSubview:image];
    }
    
    for (int i = 0; i < 5-number; i++) {
        
        UIImageView *image = [[UIImageView alloc]initWithFrame:CGRectMake(number*40*Bili+i*40*Bili, 0, 40*Bili, 40*Bili)];
        image.image = [UIImage imageNamed:@"弹窗评价-normal"];
        [self.pjView addSubview:image];
    }
#warning 暂时不加了
    //新增加密的小图标
    //    if([_myModel.isEncrypt integerValue]==1){
    //        _lockImg.hidden = NO;
    //    }
    
    
}



+ (SchoolTableViewCell *)cellWithTableView:(UITableView *)tableView{
    
    static NSString *ident = @"cell";
    
    SchoolTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ident];
    
    if (!cell) {
        
        cell = [[SchoolTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ident];
        //        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        
    }
    return cell;
}


@end
